package com.itheima.mystream;

import java.util.*;
import java.util.stream.Stream;

/**
 * Stream流的获取
 单列集合 : 集合对象.stream();
 双列集合 : 不能直接获取,需要间接获取
 集合对象.keySet().stream();
 集合对象.entrySet().stream();
 数组     :
 Arrays.stream(数组名);
 同种数据类型的多个数据:
 Stream.of(数据1,数据2,数据3......);
 */
public class Demo3 {
    public static void main(String[] args) {
        ArrayList<String> list = new ArrayList<>(List.of("张三丰","张无忌","张翠山","王二麻子","张良","谢广坤"));
        Stream<String> stream = list.stream();
        stream.forEach(s -> System.out.println(s));
        //双列集合,双列集合无法通过直接遍历来获取
        HashMap<String,Integer> hs = new HashMap<>(Map.of("zhangsan",12,"lisi",21,"wangwu",22,"zhaoliu",20));
        Set<String> key = hs.keySet();
        key.stream().forEach(s-> System.out.println(s));//打印出来的是键
        Collection<Integer> values = hs.values();
        values.stream().forEach(s-> System.out.println(s));//打印出来的是值
        //通过键值对来进行遍历
        Set<Map.Entry<String, Integer>> entries = hs.entrySet();
        entries.stream().forEach(s-> System.out.println(s.getKey()+"..."+s.getValue()));
    }
}
